package base

import "traning/algorithm/utility"

func NewRightBigHeap(limit int) *RightBigHeap {
	return &RightBigHeap{arr: make([]int, limit), size: 0, limit: limit}
}

type RightBigHeap struct {
	arr []int
	limit int
	size int
}

func (h *RightBigHeap) Push(val int) {
	h.arr[h.size] = val
	h.size++
}

func (h *RightBigHeap) Pop() int {
	maxIndex := 0
	for i:=1; i<h.size; i++ {
		if h.arr[i] > h.arr[maxIndex] {
			maxIndex = i
		}
	}
	ans := h.arr[maxIndex]
	utility.Swap(h.arr, maxIndex, h.size-1)
	h.size--
	return ans
}

func (h *RightBigHeap) IsFull() bool {
	return h.size == h.limit
}

func (h *RightBigHeap) IsEmpty() bool {
	return h.size == 0
}
